# -*- coding: utf-8 -*-
"""
Created on Thu Sep  8 16:30:33 2022

@author: wulong
"""
'transform state and input sequence that sends to other fast empcs'

'tag = 1 indicates this is first time of iteration'
'data comes from last time step'
'tag != 1 indicates this is not first time of iteration'
'data comes from last iterative step'

import numpy as np

def fast_x_u(pred_horzn, pred_horzn_2, state_bnds_2, input_bnds_2, tag, i):
    
    if tag == 1 and i != 0:
        if pred_horzn >= pred_horzn_2:
            delta_pred = pred_horzn - pred_horzn_2
            state_bnds_2_temp_1 = np.delete(state_bnds_2, 0, axis=0)
            state_bnds_2_temp_2 = np.tile(state_bnds_2[-1,:], (delta_pred+1, 1))
            state_bnds_2_new = np.append(state_bnds_2_temp_1, state_bnds_2_temp_2, axis=0)
            
            input_bnds_2_temp_1 = np.delete(input_bnds_2, 0, axis=0)
            input_bnds_2_temp_2 = np.tile(input_bnds_2[-1,:], (delta_pred+1, 1))
            input_bnds_2_new = np.append(input_bnds_2_temp_1, input_bnds_2_temp_2, axis=0)
        else:
            state_bnds_2_temp = np.delete(state_bnds_2, 0, axis=0)
            state_bnds_2_new = state_bnds_2_temp[:pred_horzn,:]
            
            input_bnds_2_temp = np.delete(input_bnds_2, 0, axis=0)
            input_bnds_2_new = input_bnds_2_temp[:pred_horzn,:]
            pass
    else:
        if pred_horzn >= pred_horzn_2:
            delta_pred = pred_horzn - pred_horzn_2
            state_bnds_2_temp = np.tile(state_bnds_2[-1,:], (delta_pred, 1))
            state_bnds_2_new = np.append(state_bnds_2, state_bnds_2_temp, axis=0)
            
            input_bnds_2_temp = np.tile(input_bnds_2[-1,:], (delta_pred, 1))
            input_bnds_2_new = np.append(input_bnds_2, input_bnds_2_temp, axis=0)
        else:
            state_bnds_2_new = state_bnds_2[:pred_horzn,:]
            
            input_bnds_2_new = input_bnds_2[:pred_horzn,:]
            pass
        pass
    
    return state_bnds_2_new, input_bnds_2_new
